package com.lkd.job;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lkd.common.VMSystem;
import com.lkd.entity.VendingMachineEntity;
import com.lkd.service.VendingMachineService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
public class AutoScanSupplyHandler {

    @Autowired
    private VendingMachineService vendingMachineService;

    @XxlJob("supplyJobHandler")
    public ReturnT<String> supplyJobHandler() {
        log.info("开始自动补货扫描");
        LambdaQueryWrapper<VendingMachineEntity> lqw = new LambdaQueryWrapper<>();
        lqw.eq(VendingMachineEntity::getVmStatus, VMSystem.VM_STATUS_RUNNING); // 售货机是运营状态

        // 查询运营中的售货机
        List<VendingMachineEntity> machineList = vendingMachineService.list(lqw);
        machineList.forEach(m -> {
           vendingMachineService.sendSupplyTask(m.getInnerCode());
        });
       return ReturnT.SUCCESS;
    }
}
